//
//  JinNavTitleButton.swift
//  lottery
//
//  Created by admin on 16/2/3.
//  Copyright © 2016年 jin. All rights reserved.
//

import UIKit

class JinNavTitleButton: UIButton {

    /*
    // Only override drawRect: if you perform custom drawing.
    // An empty implementation adversely affects performance during animation.
    override func drawRect(rect: CGRect) {
        // Drawing code
    }
    */
    override func titleRectForContentRect(contentRect: CGRect) -> CGRect {
        
        return CGRectMake(0, 0, 80, 44)
    }
    override func imageRectForContentRect(contentRect: CGRect) -> CGRect {
        return CGRectMake(80, 15, 16, 16)
    }
    var angle:CGFloat = -CGFloat(M_PI) * 0.5
    override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
        super.touchesBegan(touches, withEvent: event)
        UIView.animateWithDuration(1, animations: {
            [unowned self] in
            self.imageView?.transform = CGAffineTransformMakeRotation(self.angle)
            self.angle = (self.angle == 0) ? -CGFloat(M_PI) * 0.5 : 0
        })
    }
}
